package uit.jee.lib.access.mapper;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import uit.jee.lib.dto.ReferenceDTO;

/**
 *
 * @author ngloc_it
 */
public class ReferenceMapper extends MapperDB{

    public ReferenceMapper() throws Exception {
        super();
    }

    private void InitReferenceDTOFromRs(ReferenceDTO ref, ResultSet  rs) throws Exception{
        if((rs != null) && (ref != null)){
            ref.setSoLuongMuon(Integer.parseInt(rs.getString(ReferenceDTO.REFERENCE_SOLUONGMUON)));
            ref.setThoiGianGiaHan(Integer.parseInt(rs.getString(ReferenceDTO.REFERENCE_THOIGIANGIAHAN)));
            ref.setThoiGianMuon(Integer.parseInt(rs.getString(ReferenceDTO.REFERENCE_THOIGIANMUON)));
            ref.setTienToiThieu(Integer.parseInt(rs.getString(ReferenceDTO.REFERENCE_TIENTOITHIEU)));
        }
    }

    public ReferenceDTO GetReference() throws Exception {
        ReferenceDTO ref = new ReferenceDTO();
        try {
            StringBuffer sql = new StringBuffer();
            sql.append("select * from booklibrary.thamso");

            PreparedStatement stmt = getConnection().prepareStatement(sql.toString());
            ResultSet rs = stmt.executeQuery();
            if (rs != null && rs.next()) {
                InitReferenceDTOFromRs(ref, rs);
            }
        } catch (Exception ex) {
            throw ex;
        }

        return ref;
    }
}
